package BitCreekLib; /**
 *
 * @author Ivan Litsvinenka & Emanuele Ricci
 * Classe che rappresenta le informazioni relative a un Peer
 *
 */

import java.net.InetAddress;


public class Host implements java.io.Serializable, IHost {

    private static final long serialVersionUID = 1L;


    /**
     * InetAddress relativo al Peer
     */
    private InetAddress address;

    /**
     * Porta su cui possono connettersi gli altri Peer
     */
    private int port;

    /**
     * Costruttore di Host
     *
     * @param address L'InetAddress dell'Host
     * @param port    La porta su cui si connetteranno gli altri peer
     */
    public Host ( InetAddress address, int port ) {
        this.setAddress ( address );
        this.setPort ( port );
    }

    public InetAddress getAddress () {
        return address;
    }

    public void setAddress ( InetAddress address ) {
        this.address = address;
    }

    public int getPort () {
        return port;
    }

    public void setPort ( int port ) {
		this.port = port;
	}


    public String toString() {
        return address.toString()+":" + String.valueOf ( port );        
    }

    @Override public boolean equals(Object compare) {
        //check for self-comparison
        if ( this == compare ) return true;
        if ( !(compare instanceof Host) ) return false;

        Host compareObj = (Host)compare;

        return ( this.address.getHostAddress().equals(compareObj.getAddress().getHostAddress()) );
        

    }

    
}
